package com.qf;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/8 19:49
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 验证码
 */@Controller
@RequestMapping("/captcha")
public class CodeController {

    /**
     * 跳转到验证码页面
     * @return
     */
    @RequestMapping("/toCode")
    public String toCode() {
        return "code";
    }

    /**
     * 校验验证码
     * @param captcha
     * @return
     */
    @RequestMapping("/test1")
    public String test1(String captcha, HttpServletRequest request) {
        //1. 从session会话中获取, 会话中保存的验证码
        String sessionCode = (String)request.getSession().getAttribute("captcha");

        //2. 使用会话中的验证码和用户输入的验证码进行比较
        if (sessionCode.equalsIgnoreCase(captcha)) {
            System.out.println("=======验证码正确!======");
        } else {
            System.out.println("=======验证码错误!======");
        }

        return "hello";
    }

}
